<template>
  <div id="login">
    <el-dialog
      title="用户登录"
      :visible.sync="loginshow"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :show-close="false"
      width="25%"
      style="top:13vh"
    >
      <el-form
        ref="form"
        :model="loginsubmit"
        style="padding:0px;"
        label-position="left"
        label-width="60px"
      >
        <!-- <div class="error" v-show="login_error">账号或密码错误！</div> -->
        <el-form-item label="用户名">
          <el-input v-model="loginsubmit.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="loginsubmit.password" type="password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="login()">登 录</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginshow: true,
      loginsubmit: {
        username: "",
        password: ""
      }
    };
  },
  methods: {
    login() {
      this.$http.post("login/login", this.loginsubmit).then(response => {
        if (response.data.statu == "success") {
          sessionStorage.setItem("user_session_id", response.data.token);
          this.$router.push("/")
        } else {
          this.$message.error("账号或密码错误！");
          this.loginshow = true;
        }
      });
    }
  }
};
</script>

<style>
 #login{
     background-color: silver;
 }
</style>